<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>登录</title>
		<meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache,no-store,must-revalidate">
    <meta http-equiv="Cache" content="no-cache">
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="component/pear/css/pear.css" />
		<link rel="stylesheet" href="admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="admin/images/background.svg" style="background-size: cover;">
		<form class="layui-form" action="javascript:void(0);" style="margin-top: 80px!important;">
			<div class="layui-form-item">
				<img class="logo" src="admin/images/rohm-logo.gif" />
				<div class="title">产量&时间管理系统</div>
				<div class="desc">
					Rohm DI Wide 制造部 V1.0.7
				</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="账 户  " type="text" name="username" lay-verify="required" hover class="layui-input" autocomplete="off"  value=""/>
			</div>
			<div class="layui-form-item">
				<input placeholder="密 码   " name="password" type="password" lay-verify="required" hover class="layui-input" autocomplete="off"  value=""/>
			</div>

			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login" load>
					登 入
				</button>
			</div>
			<div class="layui-form-item">
				<button type="reset" class="pear-btn pear-btn-success" style="background-color:antiquewhite!important;color: darkgray!important; border-color: antiquewhite;" >
					重 置
				</button>
			</div>



		</form>




		<!-- 资 源 引 入 -->
		<script src="component/layui/layui.js"></script>
		<script src="component/pear/pear.js"></script>
		<script>
			// 加载自定义模块,检查浏览器和token
			layui.extend({
        myheader:'{/}lay-ext/myheader'
      })

			layui.use(['form', 'button', 'popup','jquery','myheader','layer','dtree'], function() {
				// 加载模块
				var form = layui.form;
				var button = layui.button;
				var popup = layui.popup;
				var $ = layui.jquery;
				var myheader= layui.myheader;
				var layer=layui.layer
				var util=layui.util
				var dtree=layui.dtree
				
				// 定义常量
				const baseUrl= myheader.baseUrl()
				var selectedMachineNo =""
				// 检查是否是IE浏览器
				myheader.isIE()

				// 清空对话数据
				sessionStorage.removeItem("mytoken");
				sessionStorage.removeItem("userinfo");
				sessionStorage.clear()

        // 登 录 提 交
				form.on('submit(login)', function(data) {
					// 表单数据对象
					// console.log(data.field);
					// 自定义 验证
					
					/// 登录
					
					let loadBtnDom

					$.ajax(baseUrl+'/user/doLogin',{
						type:'post',
						data: data.field,
						timeout:10000,
						// crossDomain:true,
						headers:{
							//键值对
							// Accept:"application/json;charset=utf-8"	//希望服务端返回什么数据
						},
						beforeSend:function(){   // 请求发送前回调函数
							loadBtnDom = button.load({
								elem:'[load]'
							})
						},
						success:function(data){		// 请求成功
							
							if(data.data.isLogin===true){
								layui.sessionData('mytoken', {
									key: 'tokenValue'
									,value: data.data.tokenValue
								});
								popup.success("登录成功",function(){
									window.location.replace("index.html")
								})
							}
							else{
								popup.failure('密码错误或用户被禁')
							}
						},
						error:function(status){
							popup.failure('服务器异常')
						},
						complete:function(){
							loadBtnDom.stop()
						}
					})
					
					/// 动画
					/*
					button.load({
						elem: '.login',
						time: 500,
						done: function() {
						
							return false;
							popup.success("登录成功", function() {
								location.href = "index.html"
							});
						}
					})*/
					return false;
				});
			})
		</script>
	</body>
</html>